<?php

require_once '../../Connections/level2/L2connect.php';
require_once '../../AjaxCall_Action_Utility/convertMSG.php';

function deleteProduct($idEncode) {
    $log = new KLogger("../../log/log.txt", KLogger::DEBUG);
    $id = "";
    $idDecode = idDecode(KeyAction::$delkey, $idEncode);
    $log->LogInfo("idDecode :" . $idDecode);
    if ($idDecode) {
        $id = $idDecode;
    } else {
        return FALSE;
    }
    $queryExecutor = new QueryExecutor();
    $sqlCount = "SELECT count(productId) FROM  sme_product WHERE sme_product.productId =$id AND sme_product.delete = '0' ";
    $countRecord = $queryExecutor->queryForString($sqlCount);
    if (intval($countRecord) == 1) {
        $sqlDel = "UPDATE sme_product  SET sme_product.delete = '1' WHERE sme_product.productId =$id LIMIT 1 ;";
        if ($queryExecutor->executeUpdate($sqlDel)) {
            $queryExecutor->close();
            return TRUE;
        } else {
            $queryExecutor->close();
            return FALSE;
        }
    } else {
        $queryExecutor->close();
        return FALSE;
    }
}
